package DAO;

import java.util.List;

import ClassesBasicas.Exames;
import Excecao.ExameInexistenteException;


public class RepositorioExame extends RepositorioBasico{
	
	
	public RepositorioExame() 
	{
		super();
	}
	
	public void atualizar(Exames exame) throws ExameInexistenteException
	{
	
		abreSessao();
		session.saveOrUpdate(exame);
		fechaSessao();
	}
	
	public void inserir(Exames exame) 
	{
		abreSessao();
		session.save(exame);
		fechaSessao();
	}

	@SuppressWarnings("unchecked")
	public void listar ()
	{
		abreSessao();
		org.hibernate.Query q = session.createQuery("from Pessoa");
		List<Exames> exames = q.list();
		for(Exames exame: exames)
		{
			System.out.println("Descricao: " + exame.getDescricao());
		}
		fechaSessao();
	}
	
	public void remover(String cpf) throws ExameInexistenteException 
	{
		abreSessao();
		Exames exame = (Exames) session.get(Exames.class,cpf);
		session.delete(exame);
		fechaSessao();
	}
	
	public Exames procurar(String cod) throws ExameInexistenteException 
	{
		abreSessao();
		Exames exame = (Exames) session.get(Exames.class,cod);
		fechaSessao();
		return exame;
	}

	public boolean existe(String cod){
		boolean existe = true;
		Exames exame = null;
		try {
			exame = procurar(cod);
		} catch (ExameInexistenteException e) {
			e.printStackTrace();
		}
		if (exame==null)
			existe = false;
		return existe;
	}
}
